Skip to main content

Get Saved Network Names

Description

The get_network_names function retrieves a list of saved Wi-Fi networks along with their autoconnect status and priority settings.

Function Signature:

def get_network_names() -> dict:

Parameters

  • None

Returns

  • dict: A dictionary containing the saved networks' names, autoconnect status, and priority.

Example Usage

network_names = get_network_names()
print(network_names)

Notes

This function uses the nmcli command-line tool to fetch the details of saved network connections. It filters for Wi-Fi (802-11-wireless) connections and returns their names, autoconnect status, and priority.

  • The subprocess.run() method is used to execute nmcli commands, which are part of NetworkManager.
  • The function returns a dictionary of saved network names and their autoconnect settings, as well as the count of saved networks.

Error Handling

  • If the nmcli command fails (e.g., due to incorrect permissions or connectivity issues), the function will catch the subprocess.CalledProcessError and return an error message along with empty network data.